// Copyright (c) Microsoft Corporation.  All rights reserved.
using System;
using System.Globalization;
using System.IO;

namespace EvenOdd
{
    class TestSecondsOrNumbers
    {
        [STAThread]
        public static int Main(string[] args)
        {
            // If no argument is supplied, test if Second is an even integer
            if (args.Length == 0)
                return TestNumber(DateTime.Now.Second);

            // If only a single numeric argument was supplied, test if it
            // is an even integer
            if (args.Length == 1)
            {
                try
                {
                    int num = Int32.Parse(args[0]);
                    return TestNumber(num);
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Please enter a numeric argument.");
                    return 1;
                }
            }
            // If two arguments are specified, the test passes if the second
            // argument is the name of a file that has been deployed
            if (args.Length == 2)
                if (File.Exists(args[1]))
                    return 0;

            // Test fails for any other cases
            return 1;
        }

        public static int TestNumber(int arg)
        {
            int remainder;
            Math.DivRem(arg, 2, out remainder);
            return remainder;
        }
    }
}

